<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>极简九宫格抽奖</title>
  <style>
    body {
      font-family: "Helvetica Neue", Arial, sans-serif;
      background: #fff;
      color: #333;
      text-align: center;
      margin: 0;
      padding: 30px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    h1 {
      font-weight: 400;
      margin-bottom: 20px;
    }
    .grid-container {
      padding: 10px;
      border: 3px solid #aaa; /* 九宫格边框 */
      border-radius: 8px;
      margin-bottom: 20px;
    }
    .grid {
      display: grid;
      grid-template-columns: repeat(3, 120px);
      grid-template-rows: repeat(3, 120px);
      gap: 10px;
    }
    .cell {
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px solid #aaa;
      border-radius: 6px;
      font-size: 14px;
      background: #fafafa;
      text-align: center;
      transition: 0.3s;
      line-height: 1.2;
    }
    .cell.active {
      background: #333;
      color: #fff;
      font-weight: bold;
      box-shadow: 0 0 10px #333 inset, 0 0 10px #666;
    }
    button {
      background: #333;
      color: #fff;
      border: none;
      padding: 10px 20px;
      border-radius: 3px;
      font-size: 16px;
      cursor: pointer;
      margin-bottom: 10px;
    }
    button:hover {
      background: #555;
    }
    #result {
      margin-bottom: 15px;
      font-size: 18px;
      font-weight: bold;
    }
    #history {
      font-size: 14px;
      color: #666;
      text-align: left;
      max-width: 400px;
      width: 100%;
      border: 1px dashed #aaa;
      padding: 10px;
      border-radius: 6px;
      background: #fafafa;
      box-sizing: border-box;
    }
  </style>
</head>
<body>
  <h1>九宫格抽奖</h1>
  <div class="grid-container">
    <div class="grid" id="grid"></div>
  </div>
  <button id="startBtn">开始抽奖</button>
  <div id="result">结果：未开始</div>
  <div id="history">历史记录：</div>

  <script>
    const prizes = [
      {name:"钢笔", price:20},
      {name:"手表", price:150},
      {name:"水杯", price:35},
      {name:"背包", price:120},
      {name:"耳机", price:200},
      {name:"书籍", price:50},
      {name:"T恤", price:80},
      {name:"咖啡券", price:30}
    ];
    const centerPrize = {name:"神秘礼盒", price:99};
    const grid = document.getElementById("grid");
    const result = document.getElementById("result");
    const history = document.getElementById("history");
    let cells = [], timer = null, current = 0, running = false;

    function createGrid() {
      for (let i = 0; i < 9; i++) {
        const cell = document.createElement("div");
        cell.className = "cell";
        let prize;
        if (i === 4) prize = centerPrize;
        else prize = prizes[i < 4 ? i : i - 1];
        cell.innerHTML = `${prize.name}<br>￥${prize.price}`;
        grid.appendChild(cell);
        cells.push(cell);
      }
    }

    function startLottery() {
      if (running) return;
      running = true;
      let rounds = Math.floor(Math.random() * 20) + 25;
      let index = 0;
      timer = setInterval(() => {
        cells[current].classList.remove("active");
        current = (current + 1) % 8;
        if (current >= 4) current++;
        cells[current].classList.add("active");
        index++;
        if (index >= rounds) {
          clearInterval(timer);
          running = false;
          const prizeText = cells[current].innerHTML.replace("<br>", " - ");
          result.innerHTML = `🎉 你抽中了：${prizeText}`;
          history.innerHTML += `<div>获得：${prizeText}</div>`;
        }
      }, 150);
    }

    document.getElementById("startBtn").addEventListener("click", startLottery);
    createGrid();
  </script>
</body>
</html>
